home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18112 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.0 KB  |  134 lines

  1. Newsgroups: omp.object,comp.lang.c++,comp.realtime,comp.dcom.telecom.tech,comp.arch.embedded
  2. Path: newsfeed.acns.nwu.edu!ftpbox!mothost!schbbs!news
  3. From: shang@corp.mot.com (David L. Shang)
  4. Subject: Re: Can OO be successful in real-time embedded systems?
  5. Reply-To: shang@corp.mot.com
  6. Organization: MOTOROLA 
  7. Date: Thu, 18 Apr 1996 23:22:05 GMT
  8. Message-ID: <1996Apr18.232205.24853@schbbs.mot.com>
  9. References: <RMARTIN.96Apr16161415@rcm.oma.com>
  10. Sender: news@schbbs.mot.com (SCHBBS News Account)
  11. Nntp-Posting-Host: 129.188.128.126
  12.  
  13. In article <RMARTIN.96Apr16161415@rcm.oma.com> rmartin@oma.com (Robert C.  
  14. Martin) writes:
  15. > In article <4kjfrh$28g@Starbase.NeoSoft.COM> timd@Starbase.NeoSoft.COM (Tim  
  16. Dugan) writes:
  17. >    Although I have no figures or measurements, I would have to say
  18. >    that I suspect that the one area where C++ is slower is that
  19. >    there is something about C++ that encourages programmers to
  20. >    perform a great deal more allocation and de-allocation of 
  21. >    memory, causing memory fragmentation and slowing the allocation/
  22. >    deallocation process.  
  23. > There is nothing about C++ that encourages programmers to perform
  24. > a great deal more allocation and de-allocation of memory.  Some
  25. > popular styles advocate this, but they advocate it in C++ as well as
  26. > other languages.  
  27.  
  28. Agreed. C++ is not the only language that advocates dynamic allocation
  29. and deallocation.
  30.  
  31. Polymorphism is one of the major characteristics of object-oriented
  32. programming. By declaring a variable
  33.  
  34.     in name "x" of class "C"
  35.  
  36. we can expect that "x" take of value of a subclass of "C". To get
  37. this polymorphism, you have to use dynamic memory allocation for
  38. "x". In C++, you use pointers. In Java or Eiffel, you use smart
  39. references.
  40.  
  41. Transframe is language originally designed for, but not limited to,
  42. embedded/real-time systems. The language does not advocate using
  43. dynamic references when they are not necessary. Even with static
  44. allocation, you can still get polymorphism, as long as the maximum
  45. size of the subclass value is known. For example, you can statcally
  46. allocate the storage for a polymorphic character variable which can
  47. take an ANSI character, an Unicode character, or a variable-length
  48. character.
  49.  
  50. Sometimes you might be required to dynamically allocate an object
  51. in large grain, but within the large piece of strage, you may not
  52. wnat to fragment the memoery into many small pieces.
  53.  
  54. Back to Roman Fietze's example:
  55.  
  56. > In my special case I built a menu system based on an own curses
  57. > implementation on pSOS. With the old C version I passed pointers to some
  58. > structures to the menu library functions. In the C++ version I build a
  59. > menu by adding menu items to a menu object, which causes many memory
  60. > copy, allocation and deallocation calls (not to give the CPU any chance
  61. > I even used a String class instead of char *'s). The other drawback is
  62. > that with the old system I could hold the text for the menu text in ROM
  63. > only (by declaring it const), but with C++ I have to copy it using e.g.
  64. > the operator+= or some constructor, and even the type specifier const
  65. > isn't a guarantee for beeing allocated in a readonly memory (ROM on
  66. > embedded systems, readonly sections e.g. on UNIX), it just says, the
  67. > variable cann only be initialized, but not changed by an assignement
  68. > operator.
  69.  
  70. If your system want to created new windows dynamically, you might need
  71. to allocate window structures dynamically. But within the window, if
  72. you do not want the window have function of dynamic configuration, e.g.
  73. adding/deleting menu items and other child windows, then, you can allocate
  74. everything statically by writing the following code:
  75.  
  76. object myWindow is FramedToplevelWindow
  77. {
  78.      object myMemu is Menu
  79.      {
  80.     object fileItem is PullDownMenu
  81.     {
  82.         string = "File";
  83.         object openItem is MenuItemString
  84.         {
  85.         string = "Open...\tCtrl+O";
  86.         };
  87.         object saveItem is MenuItemString
  88.         {
  89.         style = (Disabled);
  90.         string = "Save...\tCtrl+s";
  91.         };
  92.     };
  93.     object editItem is PullDownMenu
  94.     {
  95.         object copyItem is MenuItemIcon
  96.         {
  97.         style = (Disabled);
  98.         icon = icon_Copy;
  99.         };
  100.         object pasteItem is MenuItemIcon
  101.         {
  102.         style = (Disabled);
  103.         icon = icon_Paste;
  104.         };
  105.         object sp1 is MenuItemSeparator
  106.     };
  107.     ...
  108.       };
  109. };
  110.  
  111. However, if you do wish to configue the menu items dynamically,
  112. for example, you may want a "recall" pull-down menu under the
  113. "file" menu-item to list all the files opened previously in
  114. history, then, you need to design your windows in a dyamaic
  115. structure in which children are allocated dynamically.
  116.  
  117. For many small handout devices, I belive that the user interface
  118. is fixed, and dynamic configuration in the final released product
  119. is not necessary. Though in the development environment (for virtual
  120. products), Transframe enables dynamic configruation for rapid
  121. prototyping.
  122.  
  123. For large and complex desktop applications, the window structure
  124. should be dynamic.
  125.  
  126. It is the decision of application, not the decision of a language,
  127. that whether dyamaic structure should be used. Therefore, a language
  128. should provide options that an application can choose.
  129.  
  130. David Shang
  131.